/*
 * @Author: your name
 * @Date: 2020-04-17 17:02:39
 * @LastEditTime: 2020-04-25 10:13:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \v-nw-h5\src\store\modules\api\userOperation\userLike\mutations.js
 */
/* shareType:1,
   shareId:1,
   storeId:0,
   userId:0,
   menuId:0,
   sendShareMsg: 0*/
import Vue from 'vue';
import store from "../../../../index";

export default {
    // 微信分享接口商家官网的
    /*pageNum: 1
    pageSize: 10
    headPromotionId: 12   ----(可不传)指定展示的推广ID,不为空则列表第一条展示该推广信息
    */
    promotionApi(state, obj) {
        let currentUser = store.getters.currentUserFn;
        let currentStore = store.getters.currentStoreFn;
        let userId = obj && obj.userId ? obj.userId : (currentUser && currentUser.userId ? currentUser.userId : 0);
        let storeId = obj && obj.storeId ? obj.storeId : (currentStore && currentStore.userId ? currentStore.userId : 0);
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/promotion/user/${userId}/store/${storeId}/list`;
        let params = {}
        if(obj && obj.headPromotionId){
            params = {
                pageNum:obj.pageNum || 1,
                pageSize: obj.pageSize || 10,
                headPromotionId:obj.headPromotionId,
            }
        }else{
            params = {
                pageNum:obj.pageNum || 1,
                pageSize: obj.pageSize || 10,
            }
        }
        Vue.prototype.xurl.getLoading(url,params).then((data) => {
            if(data.success){
                this.commit('dealPromotionData',data);
                if(obj && obj.successFn){
                    obj.successFn();
                }
            } else if(data.errMsg){
                console.log(data.errMsg)
            }else{
                this.$root.$emit("toast",{msg:'获取页面信息出错'})
            }
        })
    },
}